#include "NewPlayerDlg.h"
#include "ui_NewPlayerDlg.h"
#include <QCloseEvent>
#include <QDebug>

NewPlayerDlg::NewPlayerDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::NewPlayerDlg)
{
  ui->setupUi(this);
  setWindowTitle("Enter Player Name");
  setWindowIcon(QIcon(QPixmap("icon.png")));
  setWindowModality(Qt::WindowModal);

  connect(ui->okayBtn, SIGNAL(clicked()), this, SLOT(onOkay()));
  connect(ui->cancelBtn, SIGNAL(clicked()), this, SLOT(onCancel()));
}

NewPlayerDlg::~NewPlayerDlg()
{
    delete ui;
}

void NewPlayerDlg::closeEvent(QCloseEvent *e)
{
  reject();
}

void NewPlayerDlg::onOkay()
{
  if ((!(ui->nameEdit->text().isEmpty())))
  {
    accept();
  }
}

void NewPlayerDlg::onCancel()
{
  reject();
}

QString NewPlayerDlg::getNewPlayerName(QWidget *parent)
{
  NewPlayerDlg dlg(parent);
  dlg.raise();
  if (dlg.exec() == QDialog::Accepted)
  {
    return dlg.ui->nameEdit->text();
  }
  else
  {
    return "";
  }
}
